package com.foo.servicesCall;

import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
import com.foo.servicesCall.NewsStub.News;
import com.foo.servicesCall.NewsStub.NewsArray;

import com.foo.servicesCall.NewsStub.GetAllNews;
import com.foo.servicesCall.NewsStub.GetAllNewsResponse;
import com.foo.servicesCall.NewsStub.GetNewsByCategory;
import com.foo.servicesCall.NewsStub.GetNewsByCategoryResponse;
import com.foo.servicesCall.NewsStub.GetNewsByKeyword;
import com.foo.servicesCall.NewsStub.GetNewsByKeywordResponse;
import com.foo.servicesCall.NewsStub.ServiceUnavailableException;

public class NewsWSClient {
			
			private static final String SERVICE_END_POINT = "http://localhost:8080/axis2/services/News";
			private NewsStub stub;

			public NewsWSClient()
			{
				try
				{
					stub = new NewsStub(SERVICE_END_POINT);
				} catch (AxisFault e) {
					System.out.println("Error while initializing stub!");
					e.printStackTrace();
				}
			}
			
			public NewsArray getAllNews()
			{
				try
				{
				GetAllNewsResponse response = new GetAllNewsResponse();
				GetAllNews data = new GetAllNews();
				
				data.setIn("");
				
				try
				{
					response = stub.getAllNews(data);
				}
				catch(RemoteException e)
				{
					System.out.println(e.getMessage());
				}
	
				return response.getGetAllNewsResponse();
				}catch(Exception e)
				{
					e.printStackTrace();
				}
				return null;
			}
			
			public NewsArray getNewsByKeyword(String Keyword)
			{
				try
				{
				GetNewsByKeywordResponse response = new GetNewsByKeywordResponse();
				GetNewsByKeyword data = new GetNewsByKeyword();
				
				data.setKeyword(Keyword);
				
				try
				{
					response = stub.getNewsByKeyword(data);
				}
				catch(RemoteException e)
				{
					System.out.println(e.getMessage());
				}
	
				return response.getGetNewsByKeywordResponse();
				}catch(Exception e)
				{
					e.printStackTrace();
				}
				return null;
			}
			
			public NewsArray getNewsByCategroy(String Category)
			{
				try
				{
				GetNewsByCategoryResponse response = new GetNewsByCategoryResponse();
				GetNewsByCategory data = new GetNewsByCategory();
				
				data.setCategory(Category);
				
				try
				{
					response = stub.getNewsByCategory(data);
				}
				catch(RemoteException e)
				{
					System.out.println(e.getMessage());
				}
	
				return response.getGetNewsByCategoryResponse();
				}catch(Exception e)
				{
					e.printStackTrace();
				}
				return null;
			}
}
